@echo off&setlocal enabledelayedexpansion
chcp 65001 1>nul 2>nul
color 07
set num=0
title 输出cmd色彩表
::获取ASCII中的27号退出键字符
for /f "tokens=1,2 delims=#" %%a in ('"prompt #h$h#$e#&for %%b in (1) do rem"') do (set ascii27=%%b[)
::枚举显示色彩范围(转换为对应的color命令的参数)
for /l %%a in (40,1,47) do (
    for /l %%b in (90,1,97) do (
        if %%a lss 10 (set num1=0%%a) else (set num1=%%a)
        if %%b lss 10 (set num2=0%%b) else (set num2=%%b)
        if !num1! equ 40 set back=0
        if !num1! equ 41 set back=4
        if !num1! equ 42 set back=2
        if !num1! equ 43 set back=6
        if !num1! equ 44 set back=1
        if !num1! equ 45 set back=5
        if !num1! equ 46 set back=3
        if !num1! equ 47 set back=7
        if !num2! equ 90 set text=8
        if !num2! equ 91 set text=c
        if !num2! equ 92 set text=a
        if !num2! equ 93 set text=e
        if !num2! equ 94 set text=9
        if !num2! equ 95 set text=d
        if !num2! equ 96 set text=b
        if !num2! equ 97 set text=f
        if !num! lss 7 (set /p =!ascii27!!num2!;!num1!m  !back!!text!  !ascii27!0m<nul&set /a num=!num!+1) else (
                echo !ascii27!!num2!;!num1!m  !back!!text!  !ascii27!0m&set num=0)
    )
)
set num=0
::枚举显示色彩范围(原始数值显示)
for /l %%a in (40,1,47) do (
    for /l %%b in (90,1,97) do (
        if %%a lss 10 (set num1=0%%a) else (set num1=%%a)
        if %%b lss 10 (set num2=0%%b) else (set num2=%%b)
        if !num! lss 7 (set /p =!ascii27!!num2!;!num1!m !num2!;!num1!!ascii27!0m<nul&set /a num=!num!+1) else (
                echo !ascii27!!num2!;!num1!m !num2!;!num1!!ascii27!0m&set num=0)
    )
)
::枚举RGB色彩范围
echo;
for /l %%b in (1,1,4) do (
    for /l %%a in (255,-13,0) do (set /p =!ascii27!48;2;255;0;%%am !ascii27!0m<nul)
    for /l %%a in (0,13,255) do (set /p =!ascii27!48;2;255;%%a;0m !ascii27!0m<nul)
    for /l %%a in (255,-13,0) do (set /p =!ascii27!48;2;%%a;255;0m !ascii27!0m<nul)
    for /l %%a in (0,13,255) do (set /p =!ascii27!48;2;0;255;%%am !ascii27!0m<nul)
    for /l %%a in (255,-13,0) do (set /p =!ascii27!48;2;0;%%a;255m !ascii27!0m<nul)
    for /l %%a in (0,13,255) do (set /p =!ascii27!48;2;%%a;0;255m !ascii27!0m<nul)
)
set /p =按任意键退出<nul&pause>nul
exit